package com.administrator.customviewtest;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.Arrays;
import java.util.List;

/**
 * Created by Administrator on 2017/6/23.
 */

public class TestAct extends AppCompatActivity {
    private RecyclerView recyclerView;
    private CommonAdapter<Boolean> adapter;
    private List<Boolean> list = Arrays.asList(false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false);
    private boolean haveChoose = false;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test2);
        recyclerView = (RecyclerView) findViewById(R.id.rv);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 5));
        adapter = new CommonAdapter<Boolean>(this, R.layout.item_test1, list) {
            @Override
            protected void convert(ViewHolder holder, Boolean aBoolean, int position) {

            }
    };
        adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                if (!list.get(position)){
                    ((ImageView) view.findViewById(R.id.img)).setImageResource(R.color.colorAccent);
                }else {
                    ((ImageView) view.findViewById(R.id.img)).setImageResource(R.color.colorPrimaryDark);
                }
                list.set(position,!list.get(position));

            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        recyclerView.setAdapter(adapter);
    }
}
